import file from '@system.file'
import featureAbility from '@ohos.ability.featureAbility';
import data_preference from '@ohos.data.preferences';

export default {
    data: {
        title: "",
    },
    onInit() {
        this.title = this.$t('strings.world');
    },
    testPut: async function () {
        console.info("LJT set start");
        var context = featureAbility.getContext();
        var mPref = await data_preference.getPreferences(context, 'test_preferences');
        await mPref.put('test_string', 'value');
        await mPref.put('test_boolean', true);
        await mPref.put('test_num', 123.123);
    },
    testGet: async function () {
        console.info("LJT Get start");
        var context = featureAbility.getContext();
        var mPref = await data_preference.getPreferences(context, 'test_preferences');
        await mPref.get('test_string', 'default', function (err, data) {
            console.info('LJT get string = ' + data);
        });
        await mPref.get('test_boolean', false, function (err, data) {
            console.info('LJT get boolean = ' + data);
        });
        await mPref.get('test_num', 321, function (err, data) {
            console.info('LJT get number = ' + data);
        });

    },
    testGetAllPromise: async function () {
        console.info("LJT GetAll promise start");
        var context = featureAbility.getContext();
        var mPref = await data_preference.getPreferences(context, 'test_preferences');
        const promise = mPref.getAll();
        promise.then((ret) => {
            console.info('LJT promise getAll test_string = ' + ret.test_string);
            console.info('LJT promise getAll test_num = ' + ret.test_num);
            console.info('LJT promise getAll test_boolean = ' + ret.test_boolean);
        }).catch((err) => {
            console.info('LJT promise getAll err = ' + err);
        });
        await promise;
    },
    testGetAllCallback: async function () {
        console.info("LJT GetAll callback start");
        var context = featureAbility.getContext();
        var mPref = await data_preference.getPreferences(context, 'test_preferences');
        await mPref.getAll(function (err, ret) {
            console.info('LJT callback getAll test_string = ' + ret.test_string);
            console.info('LJT callback getAll test_num = ' + ret.test_num);
            console.info('LJT callback getAll test_boolean = ' + ret.test_boolean);
        });
        mPref.getAll(function(err,ret){})
    },
    testClear: async function () {
        console.info("LJT Clear start");
        var context = featureAbility.getContext();
        var mPref = await data_preference.getPreferences(context, 'test_preferences');
        await mPref.clear(function (err, data) {
            console.info('LJT clear success err=' + err);
            console.info('LJT clear success data=' + data);
        });
    }
}



